package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.MissionCenterAddDTO;
import org.jsola.hr.dto.MissionCenterUpdateDTO;
import org.jsola.hr.entity.MissionCenterDO;
import org.jsola.hr.query.MissionCenterQuery;
import org.jsola.hr.service.IMissionCenterService;
import org.jsola.hr.vo.MissionCenterVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 任务调度中心任务表
 *
 * @author zhr
 */
@Component
public class MissionCenterTestHelper extends BaseTestHelper {
    
    @Autowired
    private IMissionCenterService missionCenterService;

    /**
     * 生成add测试数据
     * @return MissionCenterAddDTO
     */
    public MissionCenterAddDTO getMissionCenterAddDTO(){
        MissionCenterAddDTO missionCenterAddDTO = new MissionCenterAddDTO();
        missionCenterAddDTO.setSubjectId(getRandomValue("text",2147483647));
        missionCenterAddDTO.setSubjectType(SafeKit.getInteger(getRandomValue("int",2)));
        missionCenterAddDTO.setState(SafeKit.getInteger(getRandomValue("tinyint",1)));
        missionCenterAddDTO.setMissionName(getRandomValue("varchar",100));
        missionCenterAddDTO.setTableHead(getRandomValue("text",2147483647));
        missionCenterAddDTO.setReceiveJson(getRandomValue("text",2147483647));
        missionCenterAddDTO.setRemark(getRandomValue("varchar",50));
        missionCenterAddDTO.setFileUrl(getRandomValue("text",2147483647));
        missionCenterAddDTO.setFileType(SafeKit.getInteger(getRandomValue("tinyint",1)));
        missionCenterAddDTO.setFileName(getRandomValue("varchar",50));
        missionCenterAddDTO.setMissionMode(getRandomValue("varchar",50));
        missionCenterAddDTO.setYear(getRandomValue("varchar",4));
        missionCenterAddDTO.setMonth(getRandomValue("varchar",2));
        missionCenterAddDTO.setTime(getRandomValue("varchar",20));
        return missionCenterAddDTO;
    }


    /**
     * 生成update测试数据
     * @return MissionCenterUpdateDTO
     */
    public MissionCenterUpdateDTO getMissionCenterUpdateDTO(MissionCenterVO missionCenterVO){
        return missionCenterService.selectDOById(missionCenterVO.getId(), SITE_ID).to(MissionCenterUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return MissionCenterQuery
     */
    public MissionCenterQuery getMissionCenterQuery() {
        MissionCenterQuery missionCenterQuery = new MissionCenterQuery();
        List<MissionCenterDO> missionCenterDOList = missionCenterService.list(new MissionCenterDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(missionCenterDOList)) {
            MissionCenterDO missionCenterDO = missionCenterDOList.get(0);
            missionCenterQuery = missionCenterDO.to(MissionCenterQuery.class);
        }
        return missionCenterQuery;
    }

    /**
     * 保存示例
     * @return MissionCenterVO
     */
    public MissionCenterVO saveMissionCenterExample(){
        MissionCenterAddDTO addDTO = this.getMissionCenterAddDTO();
        MissionCenterVO missionCenterVO = missionCenterService.save(addDTO,buildTokenUser());
        return missionCenterVO;
    }


}

